//题意：给定一个长度为n(<=50000)序列，求长度为m=5的严格递增序列的个数
//
//题解：很容易想到O(n^2*m)的dp，要优化。我们可以考虑按大小从小到大排序（如果
//      相同的按位置从大到小排），然后一个一个插入，然后求当前状态f[i][j]的
//      时候就可以用数据结构将之前的（都比它小）f[p][j-1]都加起来就是f[i][j]。
//      可以用m个树状数组维护。
//
//统计：3344ms
//
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class data
{
	int value; int pos;
}

class dataComparator implements Comparator<data> {

	@Override
	public int compare(data o1, data o2) {
		if (o1.value < o2.value || (o1.value == o2.value && o1.pos > o2.pos)) return -1;
		if (o1.value > o2.value || (o1.value == o2.value && o1.pos < o2.pos)) return +1;
		return 0;
	}

}

//public class Main {  // for submit
public class poj3378 {
	static int maxn = 50100;
	static int maxm = 7;
	static data da[] = new data[maxn];
	static BigInteger bit[][] = new BigInteger[maxn][maxm];

	static int n;
	static int m = 5;

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		for (int i = 0; i < maxn; i++) da[i] = new data();

		while (in.hasNext()) {
			n = in.nextInt();
			for (int i = 1; i <= n; i++) {
				da[i].value = in.nextInt();
				for (int j = 1; j <= m; j++) bit[i][j] = BigInteger.ZERO;
				da[i].pos = i;
			}
			Arrays.sort(da, 1, n + 1, new dataComparator());

			BigInteger ans = BigInteger.ZERO;
			for (int i = 1; i <= n; i++) {
				bit_update(1, da[i].pos, BigInteger.ONE);
				for (int j = 2; j <= m; j++) {
					BigInteger sum = bit_prefix_sum(j - 1, da[i].pos - 1);
					if (j == m) ans = ans.add(sum);
					else        bit_update(j, da[i].pos, sum);
				}
			}
			out.println(ans);
			System.out.println(ans);
		}
		in.close();
		out.close();
	}

	private static void bit_update(int k, int id, BigInteger delta) {
		for (; id <= n; id += lowbit(id)) bit[id][k] = bit[id][k].add(delta);
	}

	private static BigInteger bit_prefix_sum(int k, int id) {
		BigInteger sum = BigInteger.ZERO;
		for (; id > 0; id -= lowbit(id))
			sum = sum.add(bit[id][k]);
		return sum;
	}

	private static int lowbit(int x) {
		return x & -x;
	}
}

